package router

import (
	"crow-samba/app/service"
	"github.com/gin-gonic/gin"
)

// GetSambaUsers 获取samba用户列表
// @Summary 获取samba用户列表
// @Description 获取samba用户列表
// @Tags user
// @Success 200 {object} response.Response{data=[]service.SambaUser} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/user/list [get]
// @Security Bearer
func GetSambaUsers(c *gin.Context) {
	userList, err := service.GetUserList()
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, userList)
}

// AddSambaUser 创建smb用户
// @Summary 创建smb用户
// @Description 创建smb用户
// @Tags user
// @Accept  application/json
// @Product application/json
// @Param data body service.AddUserRequest  true "用户名，密码"
// @Success 200 {object} response.Response{data=string} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/user [post]
// @Security Bearer
func AddSambaUser(c *gin.Context) {
	var userInfo service.AddUserRequest
	err := c.Bind(&userInfo)
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	response, err := service.AddUser(userInfo)
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, response)
}

// DeleteSambaUser 删除指定用户
// @Summary 删除指定用户
// @Description 删除指定用户
// @Tags user
// @Param user_name path string true "用户名"
// @Success 200 {object} response.Response{data=string} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/user/{user_name} [delete]
// @Security Bearer
func DeleteSambaUser(c *gin.Context) {
	userName := c.Param("user_name")
	response, err := service.DeleteUser(userName)
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, response)
}
